

var request = require('request')
var token = 'DgMKVux3pgci:JZbrR7y1FBX2PVF07PC5Wut1ND::Q2TAuHfa3UCsIYdvAju5qRBvN8:BqrJ9gMnYkBHKfbKhP3bKhn7jrvD'


// https://wechat.sibumbg.cn/api/member/refresh
// http://120.77.63.129:8080/order/listSellerWaitingDeliver?pageSize=7&currentPage=1&isMerge=0
// http://120.77.63.129:8080/order/listBuyerWaitingDeliver?pageSize=5&currentPage=1
var options = {
  method:'GET',
  url:'https://wechat.sibumbg.cn/api/product/list?pageSize=15&categoryId=513&currentPage=1',
  // url : 'https://wechat.sibumbg.cn/api/product/get/9d4954df-af64-4ad5-91a0-7fa5497e654a',
  port:443,
  rejectUnauthorized: false  , // 跳过https验证
  headers: {
    'User-Agent': 'request',
    'wesale-token' : token,
    'Content-Type': 'application/json',
  }
}

// 查看某个商品的库存
var stock = 0
const run  = ()=>{
  request(options,function(error, response, body){
    var d = new Date()
    var res = JSON.parse(body);
    let {result:{data},errorCode} = res
    var _stock = data.reduce((init,curr)=>{
      init += curr.stock
      return init 
    },0)
    console.log(_stock)
    // var _stock = data.result['stock']
    console.log(d.getHours().toString() +':'+ d.getMinutes()+":"+d.getSeconds())
    console.log("剩余库存数：",_stock)
    if(stock) {
      console.log('每10秒减少:',(stock-_stock))
      // console.log('以6为基数:',((stock-_stock)/6))
    }
    stock = _stock
  })
}
var stockTer = setInterval(function(){
  run()
},10000)
run()

































